using System;
using System.Collections.Generic;
using System.Text;

using System.Management.Automation;

namespace Microsoft.PowerShell.CmdletManagement
{
    [Cmdlet(VerbsCommon.Remove, "PsSpecCmdletParameterSetEntry", SupportsShouldProcess = true)]
    public class RemoveParameterSetEntryCommand : Cmdlet
    {
        [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)]
        public int Id
        {
            get { return parameterSetEntryId; }
            set { parameterSetEntryId = value; }
        }
        private int parameterSetEntryId = 0;

        [Parameter(Mandatory = false)]
        public String ServiceUri
        {
            get
            {
                return _serviceUri;
            }
            set
            {
                _serviceUri = value;
            }
        }
        private string _serviceUri = PsSpecCmdletUtils.Constants.ServiceUri;


        protected override void ProcessRecord()
        {
            if (ShouldProcess(
                String.Format("{0}", ServiceUri),
                String.Format(resources.RemovePsSpecCmdletParameterSetEntryShouldProcess, Id)))
            {
                PsSpecCmdletService.CmdletService service =
                    new PsSpecCmdletService.CmdletService();
                service.Url = ServiceUri;
                
                service.UseDefaultCredentials = true;

                try
                {
                    service.RemovePsSpecCmdletParameterSetEntry(Id);
                }
                catch (System.Web.Services.Protocols.SoapException e)
                {
                    WriteError(new ErrorRecord(e, "SERVICE_ERROR", ErrorCategory.InvalidOperation, Id));
                }
            }
        }
    }
}
